package com.neuedu.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.neuedu.model.po.Candidate;
import com.neuedu.model.service.VoteService;

@Controller
public class BaomingController {

	@Autowired
	private VoteService voteService;
	
	@RequestMapping(value="/candidates",method=RequestMethod.POST)
	public @ResponseBody String baoming(Candidate candidate,@RequestParam MultipartFile[] upload,HttpServletRequest request){
		
		//测试2
		//D:\apache-tomcat-8.0.50-windows-x64\apache-tomcat-8.0.50\webapps\wechatvote\img
		String uploadpath = request.getServletContext().getRealPath("/img");
//		String uploadpath = "E://images";
		voteService.saveCandidate(candidate, upload, uploadpath);
		//{"result",true}
		return "{\"result\":true}";
	}
}
